<template lang="html">
  <div class="box">
        <div class="body">
          <el-table :data="tableData.list" style="width: 100%">
              <el-table-column label="市代名称" prop="company" align="center" width=""></el-table-column>
              <el-table-column label="负责人" prop="leader" align="center" width=""></el-table-column>
              <el-table-column label="电话" prop="phone" align="center" width=""></el-table-column>
              <el-table-column label="运营库存" align="center" width="">
                <template slot-scope="scope">
                  <el-button  @click="getSupplyMate(scope.row)" type="primary" size="mini" plain>查看详情</el-button>
                </template>
              </el-table-column>
              <el-table-column label="物料补充记录" align="center" width="">
                <template slot-scope="scope">
                  <el-button @click="onshow(scope.row)" type="primary" size="mini" plain>查看详情</el-button>
                </template>
              </el-table-column>
          </el-table>
        </div>
        <div class="page_box">
            <el-pagination class="page" layout="prev, pager, next"
              @current-change="switchPage" :page-count='tableData.rows' >
            </el-pagination>
        </div>

        <el-dialog title="运营库存" :visible.sync="dialogTableVisible">
          <el-table :data="gridData">
            <el-table-column property="company" align="center" label="地区"></el-table-column>
            <el-table-column property="name" align="center" label="物料名称"></el-table-column>
            <el-table-column property="ration" align="center" label="期初配给"></el-table-column>
            <el-table-column property="materiel_stock" align="center" label="剩余库存"></el-table-column>
          </el-table>
        </el-dialog>

        <el-dialog title="物料补充记录" :visible.sync="dialogTableVisible2">
          <el-table :data="gridData1.list">
            <el-table-column property="sm_name" align="center" label="供应商"></el-table-column>
            <el-table-column property="leader" align="center" label="物料名称">
                <template slot-scope="scope">
                  <p v-for="i,k in scope.row.detail" :key="k">{{i.materiel}}</p>
                </template>
            </el-table-column>
            <el-table-column property="phone" align="center" label="申请数量">
              <template slot-scope="scope">
                <p v-for="i,k in scope.row.detail" :key="k">{{i.num}}</p>
              </template>
            </el-table-column>
            <el-table-column property="create_time" align="center" label="申请时间"></el-table-column>
            <el-table-column property="audit_time" align="center" label="通过时间"></el-table-column>
            <el-table-column property="over_time" align="center" label="完成时间"></el-table-column>
          </el-table>
          <div class="page_box">
            <el-pagination class="page" layout="prev, pager, next"
              @current-change="onpage" :page-count='gridData1.rows' >
            </el-pagination>
          </div>
        </el-dialog>



  </div>
</template>

<script>
export default {
  data(){
    return {
      tableData: [],
      gridData: [],
      gridData1: [],
      dialogTableVisible:false,
      dialogTableVisible2:false,
    }
  },
  created(){
    this.mateList()
  },
  methods:{
    mateList(page = 1){
      this.$http3.mateList({page}).
      then(res=>{
        this.tableData =
        res.data.code == 1?
        res.data.data:[]
      })
    },
    switchPage(p){
      this.mateList(p)
    },
    getSupplyMate(e){
      this.dialogTableVisible = true;
      this.$http3.getSupplyMate({
        gid: e.gid
      }).then(res=>{
        this.gridData =
        res.data.code == 1?
        res.data.data:[]
      })
    },
    onshow(e){
      this.dialogTableVisible2 = true;
      this.currentRow = e;
      this.applyMate()
    },
    applyMate(page = 1){
      this.$http3.applyMate({
        gid: this.currentRow.gid,
        page: page
      }).then(res=>{
        this.gridData1 =
        res.data.code == 1?
        res.data.data:[]
      })
    },
    onpage(p){
      this.applyMate(p)
    }



  }
}
</script>

<style lang="css" scoped>
@import "../../my-style/app.css";

/deep/ .el-input-group__append, .el-input-group__prepend{
  background-color: #3498E9;
  border: none;
  color: white;
}

.preview-img{
  display: block;
  width: 100%;
  height: 30px;
}
.header{
  margin-bottom: 10px
}
.page_box{
  text-align: center;
}
</style>
